<extend name="Public/base"/>
<block name="content">
<h3 class="col-md-8">采集管理</h3>
<form id="import-form" class="form-horizontal"  method="post" id="import-form">
<div class="row" >	
	<div class="col-lg-12">
		<div class="panel panel-default">
	        <div class="panel-heading">
	            设置参数
	            <a class="pull-right" title="" data-toggle="tooltip" data-perform="panel-collapse" onclick="$('#set-box').toggle('slow')" href="javascript:;" data-original-title="显示/隐藏">
				<em class="fa fa-minus"></em>
				</a>
	        </div>
	     	<div class="panel-body" id="set-box">     		
	     		<div class="col-lg-4">      
		    		<div class="form-group">	
		    			<label class="col-sm-3 control-label">所属艺术家</label>
		    			<div class="col-sm-9">
		    				<div class="input-group">
		    					<input type="text" class="hide" id="artist-id" name="artist_id" value="0">	
		    					<input type="text" class="form-control" id="artist-name" name="artist_name"  value="<{$data.artist_name|default='佚名'}>">	
								<a href="#" class="input-group-addon ajax-find" rel="artist">
		                         	<span class="fa-search fa"></span>
		                    	</a>
		                    </div>
		    			</div>	
		            </div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">所属曲风</label>
						<div class="col-sm-9">
							<select name="genre_id" class="form-control">
			        		<volist name=":get_genre_tree()" id="genre">	        			
			            		<option value="<{$genre.id}>"><{$genre.title_show}></option>
			        		</volist>
							</select>
						</div>	
					</div> 
					
					<div class="form-group">	
		    			<label class="col-sm-3 control-label">所属专辑</label>
		    			<div class="col-sm-9">
		   					<div class="input-group">
		    					<input type="text"  class="hide" name="album_id" id="album-id" value="0">
		    					<input type="text" class="form-control"  name="album_name" id="album-name" value="单曲">
								<a href="#" class="input-group-addon ajax-find" rel="album">
		                         	<span class="fa-search fa"></span>
		                    	</a>
		                    </div>
		    			</div>	
		    		</div>
		    		
		    		<div class="form-group">		
		    			<label class="col-sm-3 control-label">所属用户</label>
		    			<div class="col-sm-3 controls">	
		    				<input type="text" class="form-control"  name="up_uid"  value="">	                   
		    			</div>	
		    			<p class="help-block col-sm-6">填写会员ID</p>	
		    	    </div>	
					     
	         	</div>
	         	
	         	<div class="col-lg-4">
	              	<div class="form-group">						
		    			<label class="col-sm-3 control-label ">试听次数</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="200-1000" name="listens">
		    			</div>
		    			<span class="help-block">整数/随机数：格式 1-200</span>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载次数</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="200-1000" name="download">
		    			</div>
		    			<span class="help-block">整数/随机数：格式 1-200</span>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载积分</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="0" name="gold">
		    			</div>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">评分</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="6" name="rater">
		    			</div>
		    			<span class="help-block"></span>
		    		</div>
	   			</div>	   			   		
	   			<div class="col-lg-4">
	   				
	   				<div class="form-group">		
						<label class="col-sm-3 control-label">推荐</label>
		    			<div class="col-sm-9 controls">
							<input class="hide" name="recommend" value="0">
							<div  class="switch-wrapper">
								<span class="switch-enable">是</span>
								<span class="switch-disable selected">否</span>	
							</div>
		                </div>	
		    	    </div>		    	    
					     
	         	</div>
				<input type="hidden" name="rule_id"  value="<{$_GET['id']}>">
	   		</div>  
	   </div>	   
	</div>
</div>
</form>
<div class="row">
    <div class="col-lg-12">
    	<div class="panel panel-default">
       		<div class="panel-heading ">
				<h5 class="inline" id="c-info">链接列表</h5>
       			<div class="btn-group pull-right">
					<a class="btn  btn-success" id="clearCache" href="javascript:;">重新采集</a>
					<a class="btn  btn-success" id="ruku" href="javascript:;">开始入库</a>
	         	</div>      			
       		</div>
    		<div class="table-responsive">
        		<table class="table table-striped table-bordered table-hover">           
            		<thead>
                		<tr> 
                            <th>列表ID</th>
            				<th>音乐名称</th>
							<th>播放地址</th>
            				<th>状态</th>
                         	<!--th class="text-center">操作</th-->
                    	</tr>
                	</thead>
                    <tbody id="item-show">
						<foreach name="musicList" item="v" key="k">
							<tr id="list-<{$k}>">			
								<td><{$k+1}></td>
								<td class="m-name"><{$v['title']}></td>
								<td class="m-name"><{$v['playUrl']}></td>
								<td class="info">未导入</td>
							</tr>
						</foreach>
                    </tbody>
                </table>
    		</div>
    		<!-- 结束 表格 -->
    		<div class="panel-footer">
				<div class="row">
					<div class="page">
						
					</div>
				</div>
            </div>    		
    	</div>
	</div>
</div>
</block>
<block name="script">
<script type="text/javascript"  src="__JS__/other.js"></script>
<script type="text/javascript">
var $doc = $('#c-info') , musicCount=<{$listCount}>;
var tr = $('#item-show').find('tr');
$('#ruku').click(function(){
	$doc.html("正在发送入库请求...");	
	$('#ruku').addClass("disabled");
	$.post("<{:addons_url('Collect://Collect/import',array('id'=>$_GET['id']))}>",$("#import-form").serialize(),function(data){
		if(data.status){
			tables = data.tables;
			$doc.html(data.info + "共【"+musicCount+"】条数据开始导入，请不要关闭本页面！");
			backup(data.tab);
			window.onbeforeunload = function(){ return "正在导入数据，请不要关闭！" }
		} else {
			topAlert(data.info,'alert-error');
			$('#ruku').removeClass("disabled");
			$doc.html("导入失败...");
		}
	})
})

function backup(tab, status){
	$.get("<{:addons_url('Collect://Collect/import')}>", tab, function(data){
		if(data.status){
			if(!$.isPlainObject(data.tab)){
				$('#ruku').removeClass("disabled");                        
				$doc.html("数据全部导入完成").focus();				
				window.onbeforeunload = function(){ return null }
				if(data.url){location.reload();}
				return;
			}
			var $id = data.tab.start;
			$('#list-'+$id).remove();
			$doc.html(data.info + '共【'+musicCount+'】条数据，剩余<b style="color:red;">【'+$id+'】</b>条数据,请不要关闭本页面！');
			backup(data.tab, tab.id != data.tab.id);
		} else {
			topAlert(data.info,'alert-error');
			$('#ruku').removeClass("disabled");
			$doc.html("立即导入");
		}
	}, "json");
}

$('#clearCache').click(function(){
	$.post("<{:addons_url('Collect://Collect/clearCache')}>",{id:<{$_GET['id']}>},function(data){
		if(data.status){
			window.location.href="<{:addons_url('Collect://Collect/start',array('id'=>$_GET['id']))}>";
		}else{
			topAlert(data.info,'alert-error');
		}
	})
})

</script>
</block>	


